home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / getpid / RCS / getpid.c,v < prev   
Encoding:
Text File  |  1989-08-31  |  2.1 KB  |  96 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.08.31.13.19.47;  author ouster;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * getpid.c --
  27.  *
  28.  *    This file is a benchmark program to measure the cost of a
  29.  *    minimal kernel call (getpid).  It should be invoked as follows:
  30.  *    
  31.  *    getpid count
  32.  *
  33.  *    Where count is the number of calls to make.  It makes that
  34.  *    many calls, then prints out the average time per call.
  35.  *
  36.  * Copyright 1989 Regents of the University of California
  37.  * Permission to use, copy, modify, and distribute this
  38.  * software and its documentation for any purpose and without
  39.  * fee is hereby granted, provided that the above copyright
  40.  * notice appear in all copies.  The University of California
  41.  * makes no representations about the suitability of this
  42.  * software for any purpose.  It is provided "as is" without
  43.  * express or implied warranty.
  44.  */
  45.  
  46. #ifndef lint
  47. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.2 89/01/07 04:12:18 rab Exp $ SPRITE (Berkeley)";
  48. #endif /* not lint */
  49.  
  50. #include <stdio.h>
  51. #include <sys/time.h>
  52. #include <sys/resource.h>
  53.  
  54. main(argc, argv)
  55.     int argc;
  56.     char **argv;
  57. {
  58.     int count, i;
  59.     struct rusage begin ,end;
  60.     struct timeval start, stop;
  61.     struct timezone tz;
  62.     int micros;
  63.     double timePer;
  64.  
  65.     if (argc != 2) {
  66.     fprintf(stderr, "Usage: getpid count\n");
  67.     exit(1);
  68.     }
  69.  
  70.     count = atoi(argv[1]);
  71.  
  72. #ifdef GETRUSAGE
  73.     getrusage(RUSAGE_SELF, &begin);
  74. #else
  75.     gettimeofday(&start, (struct timezone *) NULL);
  76. #endif
  77.  
  78.     for (i = 0; i < count; i++) {
  79.         (void) getpid();
  80.     }
  81. #ifdef GETRUSAGE
  82.     getrusage(RUSAGE_SELF, &end);
  83.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  84.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  85.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  86.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  87. #else
  88.     gettimeofday(&stop, (struct timezone *) NULL);
  89.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  90.         + stop.tv_usec - start.tv_usec;
  91. #endif
  92.     timePer = micros;
  93.     printf("Time per iteration: %.2f microseconds\n", timePer/count);
  94. }
  95. @
  96.